Public Class frmPrintPolice

    Protected formStatus As Boolean = False

    Delegate Sub delGenerateReport()

    Private Sub frmPrintPolice_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        loadProvince()
        formStatus = True
        cbbProvince_SelectedIndexChanged(sender, e)
    End Sub

    'Private Sub loadOrganization(ByVal inRBNName As String, ByVal inOrganizationID As String)
    '    Dim sumOrganization As New PoliceHealthClass.ManageReportControl()
    '    Dim organizationDS As New System.Data.DataSet()
    '    organizationDS = sumOrganization.getSummaryReportOrganization(inOrganizationID, inRBNName)
    '    With cbbOrganization
    '        .DataSource = organizationDS.Tables("SummaryReportOrganization")
    '        .DisplayMember = "organization_name_tha"
    '        .ValueMember = "organization_id"
    '    End With
    'End Sub

    Private Sub loadOrganization(ByVal inProvinceID As String)
        Dim sumOrganization As New PoliceHealthClass.ManageReportControl()
        Dim organizationDS As New System.Data.DataSet()
        organizationDS = sumOrganization.getReportOrganizationByProvince(inProvinceID)
        With cbbOrganization
            .DataSource = organizationDS.Tables("PrintPoliceOrganization")
            .DisplayMember = "organization_name_tha"
            .ValueMember = "organization_id"
        End With
    End Sub

    Private Sub loadProvince()
        Dim sumProvince As New PoliceHealthClass.ManageReportControl()
        Dim provinceDS As New System.Data.DataSet()
        provinceDS = sumProvince.getProvince()
        With cbbProvince
            .DataSource = provinceDS.Tables(0)
            .DisplayMember = "province_name_tha"
            .ValueMember = "province_id"
        End With
    End Sub

    Private Sub cbbProvince_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbbProvince.SelectedIndexChanged
        If formStatus Then
            'loadOrganization("rbnAmphur", cbbProvince.SelectedValue & "000")
            loadOrganization(cbbProvince.SelectedValue)
        End If
    End Sub

    Private Sub GenerateReport()
        Dim sumReport As New PoliceHealthClass.ManageReportControl()
        Dim sumDS As New System.Data.DataSet()
        sumDS = sumReport.getPrintPoliceReport(cbbOrganization.SelectedValue)
        Dim currentReport As New PrintPolice()

        currentReport.SetDataSource(sumDS.Tables("PrintPoliceReport"))

        crvPrintPoliceReport.ReportSource = currentReport
        crvPrintPoliceReport.Zoom(74)
        crvPrintPoliceReport.Refresh()
    End Sub

    Private Sub btnShowReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowReport.Click
        ConnectionString.ShowLoadingForm()
        Me.Invoke(New delGenerateReport(AddressOf GenerateReport))
        ConnectionString.TerminateLoadingForm()
        'GenerateReport()
    End Sub

End Class